import axios from "axios";

const service=axios.create({
    baseURL:'http://localhost:80',
    timeout: 50000,
    withCredentials: true,
    headers: {
        'Content-Type': "application/json",
        'Access-Control-Allow-Origin':'http://localhost:3000',
        'Access-Control-Allow-Headers':'X-Requested-With,Content-Type',
        'Access-Control-Allow-Methods':'PUT,POST,GET,DELETE,OPTIONS',
    }
})
service.interceptors.response.use(
    response=>{
        //判断是否有token 保存token
        const auth = response.headers['authentication'] || response.headers['Authentication'];
        if (auth){
            localStorage.setItem("auth",auth)
        }
        return response.data
    }
)

service.interceptors.request.use(
    config=>{
        // @ts-ignore
        config.headers.Authentication =localStorage.getItem("auth")
        return config;
    }
)

export default service
